﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SSE.Models;

namespace SSE.Controllers
{
    public class LoginController : Controller
    {
        //
        // GET: /Login/
        public static Boolean WrongPWD = true;
        public static string adminName = "管理员";
        public static int adminID;

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Login(FormCollection form)
        {
            //通过控件的name获取值
            int usrId = int.Parse(form["UserID"]);
            string pwd = form["Password"];
            var UsrToLogin = from u in sseEntities.GetInstance().User where u.UserID == usrId select u;
            if ((UsrToLogin.Count() != 0) && pwd.Equals(UsrToLogin.First().Password.ToString()))
            {
                adminName = UsrToLogin.First().Username;
                adminID = UsrToLogin.First().UserID;
                WrongPWD = false;
                return RedirectToAction("Index", "State");
            }
            return View("Alert");
        }

        public ActionResult Alert()
        {
            return View();
        }
    }
}
